<?php
/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 15/6/18
 * Time: 上午11:13
 */

class PubOss {

    public static function getGameList(){
        $result = self::api('getGameList', array(), 'oss');
        $gameList = array();

        if($result['state']){
            foreach($result['data'] as $v){
                $gameList[$v['id']] = $v['name'];
            }
        }

        return $gameList;
    }

    public static function api($method, $data = array(), $for='platform'){
        $config = isset(Yii::app()->params['ApiConfig'][$for]) ? Yii::app()->params['ApiConfig'][$for] : Yii::app()->params['ApiConfig']['platform'];

        $data['time'] = time();
        $data['key'] = $config['key'];
        $data['method'] = $method;
        ksort($data);
        $data['sign'] = md5(http_build_query($data));
        unset($data['key']);
        $re = PubFunc::request($config['url'], $data, 10, $config['hosts']);

        if($re['code'] != 200){
            $result = array('state' => false, 'code' => 505, 'message' => 'System_Error');
        }else{
            $result = json_decode($re['result'], true);
            if(!$result){
                $result = array('state' => false, 'code' => 506, 'message' => 'System_Error');
            }
        }
        return $result;
    }

} 